﻿using System;
using Teigha.DatabaseServices;

namespace SmartPlant.CADView
{
    public static class CadHelper
    {
        public static Database OpenFile(string sFilePath)
        {
            var database = new Database(buildDefaultDrawing: false, noDocument: false);
            try
            {
                string text = sFilePath.Substring(sFilePath.Length - 4);
                text = text.ToUpper();
                if (text.EndsWith(".DWG"))
                {
                    database.ReadDwgFile(sFilePath, FileOpenMode.OpenForReadAndAllShare, allowCPConversion: false, "");
                }
                else if (text.EndsWith(".DXF"))
                {
                    database.DxfIn(sFilePath, "");
                }
                return database;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
